﻿Imports Excel1 = Microsoft.Office.Interop.Excel, Microsoft.VisualBasic.FileIO, PowerPoint1 = Microsoft.Office.Interop.PowerPoint, Word1 = Microsoft.Office.Interop.Word

''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
''' <features></features>
''' <stepthrough>Disabled</stepthrough>
Public NotInheritable Class Utilities
    Private Sub New()
    End Sub

    Public Class FileDialogFilters
        Public Const XML As String = "XML files (*.xml)|*.xml|All files (*.*)|*.*"
    End Class


End Class



Partial Class Utilities


    ''' <summary>
    ''' Perform spell check operation on control content.
    ''' This operation displays the results of the spell
    ''' check.  
    ''' 
    ''' Alternatively, the function could be set to return
    ''' a string and the results string could be returned
    ''' to the caller
    ''' </summary>
    ''' <param name="IsTextBox"></param>
    ''' <param name="oAlwaysSuggest"></param>
    ''' <param name="oIgnoreUpperCase"></param>
    ''' <remarks>The Reason this is here is Because I Remove the References to Microsoft Word from Aaron.Main into Here </remarks>
    ''' <stepthrough></stepthrough>
    Public Shared Sub CheckSpelling(ByVal IsTextBox As TextBoxBase, Optional ByVal oAlwaysSuggest As Boolean = True, Optional ByVal oIgnoreUpperCase As Boolean = False)
        Dim emptyItem As Object = System.Reflection.Missing.Value
        Dim ErrorCountMessage As String = String.Empty
        Dim WordApp As New Microsoft.Office.Interop.Word.Application() With {.Visible = False, .ShowWindowsInTaskbar = False}

        If IsTextBox.Text.Length > 0 Then
            Dim WordDoc As Microsoft.Office.Interop.Word._Document = WordApp.Documents.Add(emptyItem, emptyItem, emptyItem, False) ' create an instance of a word document
            WordDoc.Words.First.InsertBefore(IsTextBox.Text) ' load the content written into the word doc
            WordDoc.CheckSpelling(Nothing, oIgnoreUpperCase, oAlwaysSuggest, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing) ' execute spell check; assumes no custom dictionaries
            ErrorCountMessage = "Spell check complete; errors detected: " & WordDoc.SpellingErrors.Count
            IsTextBox.Text = WordDoc.Range(0, WordDoc.Characters.Count - 1).Text.Replace(vbCr, C1) ' return corrected text to control's text area
        Else
            ErrorCountMessage = "Unable to spell check an empty text box." ' if nothing was typed into the control, abort and inform user
            ' return report on errors corrected
            ' - could either display from the control or change this to 
            ' - return a string which the caller could use as desired.
            MessageBox.Show(ErrorCountMessage, "Finished Spelling Check")
        End If
        WordApp.Quit(False, emptyItem, emptyItem)
    End Sub





    ' ''' <summary>
    ' ''' Properly Creates Files that have Extentions Generaly this Involves haveing the Actual Program Create them
    ' ''' </summary>
    ' ''' <param name="FileType">A Selection of All File Extentions that Work with this Sub</param>
    ' ''' <param name="URL">The URL for the New File</param>
    'Public Sub CreateSpecialFile(ByVal FileType As FSObject.FSType, ByVal URL As String)
    '    Dim EXT As String
    '    Select Case FileType
    '        Case SpecialFile.Excel : EXT = ".xls"
    '        Case SpecialFile.PowerPoint : EXT = ".ppt"
    '        Case SpecialFile.Word : EXT = ".doc"
    '        Case Else : Throw New ApplicationException("{FileType} was not a legal [SpecialFile]")
    '    End Select


    '    If Not File_Folder.IsValid_Path(File_Folder.Path_Type.Path, URL) Then
    '        Exit Sub
    '    ElseIf New FS.File_Folder(URL & EXT).Exists Then
    '        VisualBasic.MsgBox("File\Folder Already Exists")
    '        Exit Sub
    '    ElseIf New FS.File_Folder(URL & EXT & "x").Exists Then
    '        VisualBasic.MsgBox("File\Folder Already Exists")
    '        Exit Sub
    '    End If

    '    Select Case FileType
    '        Case SpecialFile.Word
    '            Dim oWord As Word1.Application, oDoc As Word1.Document, missing As Object = System.Type.Missing

    '            oWord = CreateObject("Word.Application")
    '            oWord.Visible = True
    '            oDoc = oWord.Documents.Add

    '            oDoc.SaveAs(URL, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)

    '            oDoc.Close()
    '            oDoc = Nothing
    '            oWord.Quit(missing, missing, missing)

    '        Case SpecialFile.Excel
    '            'http://www.dreamincode.net/forums/topic/125690-create-a-new-excel-file/

    '            Dim xlApp As Excel1.Application = New Excel1.Application, xlBook As Excel1.Workbook = xlApp.Workbooks.Add
    '            Dim xlSheet As Excel1.Worksheet = xlBook.Worksheets.Add

    '            '  xlSheet.Cells(1, 1).Value = Text1.Text  :  xlSheet.Cells(1, 2).Value = Text2.Text
    '            xlSheet.SaveAs(URL)
    '            xlApp.Quit() : xlApp = Nothing : xlBook = Nothing : xlSheet = Nothing

    '        Case SpecialFile.PowerPoint
    '            '?http://support.microsoft.com/kb/303717

    '            Dim oApp As PowerPoint1.Application, oPres As PowerPoint1.Presentation
    '            oApp = New PowerPoint1.Application() With {.WindowState = PowerPoint1.PpWindowState.ppWindowMinimized}
    '            oPres = oApp.Presentations.Add
    '            oPres.SaveAs(URL, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue)
    '            oPres.Close() : oPres = Nothing : oApp.Quit() : oApp = Nothing : GC.Collect()
    '    End Select
    'End Sub





End Class
